<?php
/**
 * Created by PhpStorm.
 * User: 84071
 * Date: 2018-08-15
 * Time: 20:56
 */
namespace app\wxapi\controller;

use app\common\controller\Wxapibase;

class Index extends Wxapibase {

    public function index(){
        //  获取团购信息
//        $ztg = $this->ztg();
//        $ltg = $this->ltg();
        $webs = array(
            'title' => $this->webdb['webname'],
            'keywords' => $this->webdb['webkeywords'],
            'description' => $this->webdb['description'],
        );
        $this->assign([
            'webs' => $webs,
//            'tuangou' => $ztg,
//            'ltuangou' => $ltg,
        ]);
        return view();
    }
    //  获取团购信息
    public function ztg(){
        $ztgdata = db('article')->alias('a')->join('article_content_101 b','b.aid = a.aid')->where('a.status=1')->where('b.pinclass','正常团')->where('b.kstims','<',time())->where('b.jietims','>',time())->limit(4)->select();
        return $this->tuanggoudata($ztgdata);
    }
    //  获取0元团信息
    public function ltg(){
        $ztgdata = db('article')->alias('a')->join('article_content_101 b','b.aid = a.aid')->where('a.status=1')->where('b.pinclass','0元团')->where('b.kstims','<',time())->where('b.jietims','>',time())->limit(4)->select();
        return $this->tuanggoudata($ztgdata);
    }
    protected function tuanggoudata($data){
        if(empty($data)){
            return $data = '';
        }
        foreach ($data as $k => $v){
            if(!empty($v['pinimg'])){
                $v['pinimg'] = imgeditadd($v['pinimg'],false);
            }
            if(empty($v['picurl'])){
                $v['picurl'] = model('Article')->where('aid',$v['paid'])->value('picurl');
            }
            $v['shichangjia'] =db('article_content_100')->where('aid',$v['paid'])->value('shichuangjia');
            if($v['pinclass'] == '0元团'){
                $v['pinmoney'] = '0';
            }
            $v['addnum'] = model('Order')->where('aid',$v['aid'])->count();
            $picurl = explode('/',$v['picurl']);
            $v['picurl3'] = '/'.$this->webdb['updir'].'/'.$v['picurl'];		//1:1的图
            $v['picurl'] = '/'.$this->webdb['updir'].'/'.$picurl['0']."/1x1_{$picurl['1']}";		//1:1的图
            $v['picurl1'] = '/'.$this->webdb['updir'].'/'.$picurl['0']."/3x4_{$picurl['1']}";		//1:1的图
            $v['picurl2'] = '/'.$this->webdb['updir'].'/'.$picurl['0']."/4x3_{$picurl['1']}";		//1:1的图
            $data[$k] = $v;
        }
        return $data;
    }

}